package com.hsjk.szwj.module.pay.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hsjk.szwj.framework.common.constant.CommonConstant;
import com.hsjk.szwj.module.pay.dal.dataobject.system.PayInterfaceConfigDO;
import com.hsjk.szwj.module.pay.dal.mysql.IPayInterfaceConfigMapper;
import com.hsjk.szwj.module.pay.enums.MchInfoTypeEnum;
import org.springframework.stereotype.Service;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/08/21 17:25
 **/
@Service
public class PayInterfaceConfigService
        extends ServiceImpl<IPayInterfaceConfigMapper, PayInterfaceConfigDO> {

//    @Resource
//    private IPayInterfaceDefineService payInterfaceDefineService;
//
//    @Resource
//    private IMchInfoService mchInfoService;
//
//    @Resource
//    private IMchAppService mchAppService;


    public PayInterfaceConfigDO getByInfoIdAndIfCode(Integer infoType, String infoId, Long ifId) {
        return getOne(new LambdaQueryWrapper<PayInterfaceConfigDO>()
                .eq(PayInterfaceConfigDO::getInfoType, infoType)
                .eq(PayInterfaceConfigDO::getInfoId, infoId)
                .eq(PayInterfaceConfigDO::getIfId, ifId)
        );
    }

    public boolean mchAppHasAvailableIfCode(Long appId, Long ifId) {
        return this.count(
                new LambdaQueryWrapper<PayInterfaceConfigDO>()
                        .eq(PayInterfaceConfigDO::getIfId, ifId)
                        .eq(PayInterfaceConfigDO::getState, CommonConstant.PUB_USABLE)
                        .eq(PayInterfaceConfigDO::getInfoId, appId)
                        .eq(PayInterfaceConfigDO::getInfoType, MchInfoTypeEnum.APP.getType())
        ) > 0;
    }
}
